package com.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.entity.User;
import com.service.impl.UserServiceImp;

/**

 * Servlet implementation class EditMessageServlet

 */
@WebServlet("/EditMessageServlet")
public class EditMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**

     * @see HttpServlet#HttpServlet()

     */
    public EditMessageServlet() {
        super();
        // TODO Auto-generated constructor stub

    }

	/**

	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

	}

	/**

	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    processRequest(request, response);
		// TODO Auto-generated method stub

	}
	protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        User user=new User();
        
        
        try {
			UserServiceImp userServiceImp=new UserServiceImp();

			int userId=Integer.parseInt(request.getParameter("userid"));
			String password=request.getParameter("password");
			String gender=request.getParameter("gender");
			String username=request.getParameter("username");
			int age=Integer.parseInt(request.getParameter("age"));
			String email=request.getParameter("email");
			String regdatetime=request.getParameter("regdatetime");
			
			
			
			user.setUsername(username);
			user.setUserId(userId);
			user.setPassword(password);
			user.setGender(gender);
			user.setAge(age);
			user.setEmail(email);
			user.setRegdatetime(regdatetime);
			userServiceImp.updateUser(user);
		} catch (Exception e) {
			e.printStackTrace();
		}
        response.sendRedirect("index.jsp");
	}


}